#!/usr/bin/perl

use strict;
use warnings;

our %Commands;

our %Settings;

our %ParameterRegExpValues;

our $LastCommandType;    #

&defineAlias( 'ses', 'q sess' );
&defineAlias( 'ls',  'q sess' );
&defineAlias( 'ps',  'q sess' );

&defineAlias( 'up',  '!svn up' );
&defineAlias( 'com', '!svn commit -m' );

&msg( '0110D', 'FOOooo' );
$Commands{&commandRegexp( "fooooo", "" )} = sub {

    if ( $ParameterRegExpValues{HELP} ) {
        ###############################
        # Put your help message here! #
        ###############################
        print <<FOOHELPEND;
----------------
Help of foo! ;-)
----------------
   __
  / _| ___   ___
 | |_ / _ \\ / _ \\
 |  _| (_) | (_) |
 |_|  \\___/ \\___/

Enjoy it!
FOOHELPEND

        $LastCommandType = "HELP";

        return 0;
    }

    my $i = 0;
    foreach (@_) {
        if ( defined $_ ) {
            print $i++ . ":" . ( ( $_ ne "" ) ? $_ : "n/a" ) . "\n";
        }
    }

    print "foo fighter!\n";

    $LastCommandType = "FOO";

    return 0;
};

&msg( '0110D', 'SHow LIBVolumes' );
$Commands{&commandRegexp( "show", "libvolume" )} = sub {

    if ( $ParameterRegExpValues{HELP} ) {
        ###############################
        # Put your help message here! #
        ###############################
        print "--------\n";
        print "show libvolumes Help!\n";
        print "--------\n";

        $LastCommandType = "HELP";

        return 0;
    }

    my @libvolumes =
      &runTabdelDsmadmc( "select volume_name, library_name from libvolumes",
        "select_vol_lib_from_libvolumes" );
    my @volumes = &runTabdelDsmadmc(
"select volume_name, stgpool_name from volumes where devclass_name != 'DISK'"
    );

    my %tmpLibvolumeHash;

    my @tmp;

    my $i;

    # array2hash
    &pbarInit( "LIBVOLUMES |", $#libvolumes, "|");
    $i = 0;
    foreach (@libvolumes) {
        my ( $volume_name, $libarry_name ) = split( /\t/, $_ );
        $tmpLibvolumeHash{$volume_name} = $libarry_name;
        &pbarUpdate($i++);
    }

    # "join"
    &pbarInit( "VOLUMES    |", $#volumes, "|");
    $i = 0;
    my $missingString = &colorString( "!MISSING!", "BOLD RED" );
    foreach (@volumes) {
        my ( $volume_name, $stgpool_name ) = split( /\t/, $_ );
        if ( defined( $tmpLibvolumeHash{$volume_name} ) ) {
#          delete $tmpLibvolumeHash{$volume_name};
        }
        else {
            push( @tmp, "$volume_name\t$stgpool_name\t$missingString" );
        }
        &pbarUpdate($i++);
    }

    &setSimpleTXTOutput();
    &universalTextPrinter( "VOLUME\tSTGPOOL\tLIBRARY", @tmp );

    $LastCommandType = "GENERAL";

    return 0;
  };

1;
